home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / uupc11ys.zip / LIB / SAFEOUT.C < prev    next >
C/C++ Source or Header  |  1993-04-06  |  3KB  |  83 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    s a f e o u t . c                                               */
  3. /*                                                                    */
  4. /*    Console I/O functions for use during interrupt processing       */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*    Since C I/O functions are not safe inside signal routines,      */
  9. /*    the code uses conditionals to use system-level DOS and OS/2     */
  10. /*    services.  Another option is to set global flags and do any     */
  11. /*    I/O operations outside the signal handler.                      */
  12. /*--------------------------------------------------------------------*/
  13.  
  14. #define __MSC                 /* Make Borland C++ 2.0 act like MS C  */
  15.  
  16. #include <stdio.h>
  17.  
  18. #ifdef WIN32
  19.     #include <windows.h>
  20.     #include <string.h>
  21. #else
  22. #if defined( FAMILYAPI )
  23.     #define INCL_NOCOMMON
  24.     #define INCL_NOPM
  25.     #define INCL_VIO
  26.     #define INCL_KBD
  27.     #include <os2.h>
  28.     #include <string.h>
  29. #else
  30.     #include <dos.h>
  31.     #include <bios.h>
  32.     #include <conio.h>
  33. #endif /* FAMILYAPI */
  34. #endif /* WIN32 */
  35.  
  36. /*--------------------------------------------------------------------*/
  37. /*                    UUPC/extended include files                     */
  38. /*--------------------------------------------------------------------*/
  39.  
  40. #include "lib.h"
  41. #include "safeio.h"
  42.  
  43. /*--------------------------------------------------------------------*/
  44. /*    s a f e o u t                                                   */
  45. /*                                                                    */
  46. /*    Outputs a string using system level calls. from MicroSoft       */
  47. /*    Programmer's Workbench QuickHelp samples                        */
  48. /*--------------------------------------------------------------------*/
  49.  
  50. void safeout( char *str )
  51. {
  52.  
  53. #ifdef _Windows
  54.    fputs( str , stdout );
  55.    return;
  56. #else
  57. #if defined( WIN32 )
  58.    HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  59.    DWORD dwBytesWritten;
  60.  
  61.    WriteFile(hStdOut, str, (DWORD)strlen(str), &dwBytesWritten, NULL);
  62.    return;
  63.    
  64. #else
  65. #if defined( FAMILYAPI )
  66.    VioWrtTTY( str, strlen( str ), 0 );
  67. #else
  68.     union REGS inregs, outregs;
  69.  
  70.     inregs.h.ah = 0x0e;
  71.     while( *str )
  72.     {
  73.         inregs.h.al = *str++;
  74.         int86( 0x10, &inregs, &outregs );
  75.     }
  76.  
  77.     safeflush();              /* Flush keyboard                      */
  78.  
  79. #endif /* FAMILYAPI */
  80. #endif /* WIN32 */
  81. #endif /* _Windows */
  82. } /* safeout */
  83.